﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 护士工作站
{
    public partial class 在院病人信息查询 : Form
    {
        public 在院病人信息查询()
        {
            InitializeComponent();
        }
        public DataSet ds = new DataSet();
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "内科")
                {
                    string m = "select Patient.PatName,Patient.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='内科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)

                if (this.treeView1.SelectedNode.Text == "外科")
                {
                    string m = "select PatName,InHospital.HosNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='外科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);

                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "妇产科")
                {
                    string m = "select PatName,InHospital.HosNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='妇产科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "儿科")
                {
                    string m = "select PatName,InHospital.HosNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='儿科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "五官科")
                {
                    string m = "select Patient.PatName,Patient.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='五官科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)

                if (this.treeView1.SelectedNode.Text == "肿瘤科")
                {
                    string m = "select PatName,InHospital.HosNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='肿瘤科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);

                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "中医科")
                {
                    string m = "select PatName,InHospital.HosNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='中医科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "传染科")
                {
                    string m = "select PatName,InHospital.HosNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='传染科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
        }



        private void 在院病人信息查询_Load(object sender, EventArgs e)
        {

        }

        private void reportViewer1_Load(object sender, EventArgs e)
        {

        }

        private void tb_cx_KeyPress(object sender, KeyPressEventArgs e)
        {


            if (e.KeyChar == 13)
            {
                if (rb_zyh.Checked)
                {
                    if (tb_cx.Text != "")
                    {
                        int size = dGV1.RowCount;

                       

                        for (int i = 0; i < size; i++)
                        {
                            if (tb_cx.Text == Convert.ToString(dGV1.Rows[i].Cells[0].Value))
                            {
                                dGV1.CurrentCell = this.dGV1.Rows[i].Cells[0];
                                dGV1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                                break;
                            
                            }

                            
                        }
                         
                    }
                        
                       
                    }
                }

            }


        }
    }

